package org.donald.sources;

import java.net.ServerSocket;
import java.net.Socket;

public class SimpleTCPServer {
    public static void main(String[] args) {
        int port = 9000; // 监听的端口号

        try (ServerSocket serverSocket = new ServerSocket(port)) {
            System.out.println("Server is listening on port " + port);

            while (true) {
                // 接受客户端连接
                Socket socket = serverSocket.accept();
                System.out.println("New client connected");

                // 启动一个新的线程来处理客户端连接
                new ClientHandler(socket).start();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
